<template>
	<view class="layout">
		<view class="content">
			<view class="countdown">
				学习倒计时：{{ countdownStore.formattedTime }}
			</view>
			
			<scroll-view scroll-y="true" class="scrollView">
				<view v-for="item in wordsList" :key="item.number">
					<view :class="[item.number == selectedId ? 'active-item' : 'item']" @click="onClickItem(item.number, item.word)">
						<view class="itemTop">
							<text>{{item.word}}</text>
							<view class="iconBtnRow">
								<view :class="[item.statu == 1 ? 'leftBtn' : 'inactive-leftBtn']"  @click.native.stop="onConfirm(item.number)">
									<uni-icons type="checkmarkempty" size="30" color="white"></uni-icons>
								</view>
								<view :class="[item.statu == 2 ? 'rightBtn' : 'inactive-rightBtn']"  @click.native.stop="onDeny(item.number)">
									<uni-icons type="closeempty" size="30" color="white"></uni-icons>
								</view>
							</view>
						</view>
						<view class="itemBottom">
							<text v-if="selectedId === item.number && showTranslation">{{item.meaning}}</text>
						</view>
					</view>

				</view>
			</scroll-view>
			
		</view>
		<view class="bottom">
			<text v-if="!isFinished">{{wordsCount()}}个单词</text>
			<view v-else class="statistics">
				<view class="statisticsItem">
					<view class="label">
						总数
					</view>
					<view class="value">
						{{ wordsList.length }}
					</view>
				</view>
				<view>|</view>
				<view class="statisticsItem">
					<view class="label">
						错误
					</view>
					<view class="value">
						{{ wrongWordsCount }}
					</view>
				</view>
				<view>|</view>
				<view class="statisticsItem">
					<view class="label">
						准确率
					</view>
					<view class="value">
						{{ accuracy }}%
					</view>
				</view>
			</view>
			<view v-if="!isFinished" class="bottomBtn" @click="startRemember">
				开始识记
			</view>
			<view v-else class="bottomBtn" @click="onSummit">
				提交
			</view>
		</view>
	
		<uni-popup ref="tipsDialog" type="center" :is-mask-click="false">
			<view class="tipsDialog">
				<view class="dialogContent">
					<view class="dialogTitle">
						温馨提示
					</view>
					<view class="textIconColumn">
						<view class="textIconRow">
							<text>认识的词点对勾,标记为:</text>
							<view class="rightBtn">
								<uni-icons type="checkmarkempty" size="20" color="white"></uni-icons>
							</view>
						</view>
						<view class="textIconRow">
							<text>不熟悉的点叉号,标记为:</text>
							<view class="wrongBtn">
								<uni-icons type="closeempty" size="20" color="white"></uni-icons>
							</view>
						</view>
					</view>
					<view class="bottomTip">
						<text>点击开始标记后会把标记\n红叉的单词进行标记学习</text>
					</view>
					
				</view>
				<uni-icons type="clear" size="100rpx" @click="onCloseDialog"></uni-icons>
			</view>
		</uni-popup>
	
		<uni-popup ref="subTimesDialog" type="center" :is-mask-click="false">
			<view class="subTimesDialog">
				<view class="dialogContent">
					<view class="dialogTitle">
						次数减少确认
					</view>
					<text>是否确认减少指导次数</text>
					<view class="btnRow">
						<view class="btnLeft" @click="onConfirmSub">
							减少
						</view>
						<view class="btnRight" @click="onRejectSub">
							不减少
						</view>
					</view>
				</view>
				<uni-icons type="clear" size="100rpx" @click="onCloseSubDialog"></uni-icons>
			</view>
		</uni-popup>
	</view>
</template>

<script setup>
	import {ref, computed} from "vue";
	import {onLoad, onUnload, onReady, onShow, onHide } from '@dcloudio/uni-app';
	import { useUserInfoStore } from '../../store';	
	import { useStudyInfoStore } from '../../store';
	import { useCountdownStore } from '../../store';
		
	//获得store实例对象
	const userInfoStore = useUserInfoStore()
	//获得store实例对象
	const studyInfoStore = useStudyInfoStore()
	
	const countdownStore = useCountdownStore()
	
	let wordsList = ref([]);
	
	let isFinished = ref(false);
	
	const tipsDialog = ref(null);
	
	const subTimesDialog = ref(null);
	
	let feedbackId = "";
	
	let inThisPage = true;
	
    //选中的单词id
    let selectedId = ref(-1);
    //是否显示中文翻译
    let showTranslation = ref(false);
	
	const timer = ref(null)
	
	//错词 计算属性
	const wrongWordsCount = computed(() => {
		return wordsList.value.filter(item => item.statu === 2).length;
	})
	
	//准确率 计算属性
	const accuracy = computed(() => {
		return (wordsList.value.filter(item => item.statu === 1).length / wordsList.value.length * 100).toFixed(2);
	})
	
	const forgettingRate = computed(() => {
		return ((1 - wordsList.value.filter(item => item.statu === 1).length / wordsList.value.length) * 100).toFixed(2);
	})
	
	// function wordsCount(){
	// 	return wordsList.value.filter(item => item.statu != 0).length;
	// }
	

	
	onLoad(async ()=>{
		//原始数据
		// let arr = getRandomItems(uni.getStorageSync("GaoKao3500"), 20);
		let arr = uni.getStorageSync(studyInfoStore.wordBankId);
		
		if(studyInfoStore.studyMode === 0){
			
			let res = undefined;
			
			/// mark01
			if(userInfoStore.userInfo.role === 0) {
				res = await uniCloud.callFunction({
					name: "getStudyedWords",
					data: {
						relateUuid: userInfoStore.userInfo.uuid,
						wordBankId: studyInfoStore.wordBankId
					}
				})
			} else if(userInfoStore.userInfo.role === 1){
				res = await uniCloud.callFunction({
					name: "getStudyedWords",
					data: {
						relateUuid: userInfoStore.selectedStudentInfo.uuid,
						wordBankId: studyInfoStore.wordBankId
					}
				})
			}
				
			let randomArr = undefined

			if(res.result === ""){
				randomArr = getOrderItems(arr, 500);
			} else {
				//提取word字段
				const tempArr = new Set(res.result.map(item => item.word));
					
				const resultArr = arr.filter(item => !tempArr.has(item.word))
				
				randomArr = getOrderItems(resultArr, 500);
			}
				
			//statu 0未选择 1确认 2否认
			wordsList.value = randomArr.map(item => {
				return {
					...item,
					statu: 0
				}
			})
			
			//正则表达式解析
			wordsList.value.map(item => {
				if(item.meaning?.includes(".")){
					let regex = /(?<=\.{1})[^\.]+?(?=[,，；]|$)/g;
					let match = item.meaning.match(regex);
					item.meaning = match?.join()
				}
			})
			
			countdownStore.startCountdown(3600);
			// countdownStore.startCountdown(10);
			
		} else if(studyInfoStore.studyMode === 1) {
			isFinished.value = true;
			//从studyInfoStore中获取选择单词列表
			let studyWordsList = studyInfoStore.studyWordsList;
			
			//根据number从词库中赛选单词
			studyWordsList.forEach((item) => {
			    wordsList.value.push(
					{
						...arr.find(word => word.number === item),
						statu: 0
					}
				)
				
			})
			
			//正则表达式解析
			wordsList.value.map(item => {
				if(item.meaning?.includes(".")){
					let regex = /(?<=\.{1})[^\.]+?(?=[,，；]|$)/g;
					let match = item.meaning.match(regex);
					item.meaning = match?.join()
				}
			})
			
			// uni.hideLoading()
			
			console.log(studyWordsList)
		}
				
		
		
	})
	
	onShow(() => {
		console.log("显示")
		inThisPage = true;
	})
	
	onHide(() => {
		console.log("隐藏")
		inThisPage = false;
	})
	
	onReady(()=>{
		console.log(studyInfoStore.studyMode)
		
		// 监听倒计时结束事件
		uni.$on('countdownFinished', () => {
		  uni.showToast({
		    title: '倒计时结束',
		    icon: 'none'
		  })
			  
		  if(inThisPage){
			uni.navigateBack()
		  }
		})
		
		if(studyInfoStore.studyMode === 0){
			tipsDialog.value.open();
			setTimeout(()=>{
				uni.setNavigationBarTitle({
					title: "学新前检测",
					success: () => {
						console.log("设置标题成功")
					},
					fail: () => {
						console.log("设置标题失败")
					}
					
				})
			}, 100);
			// 监听事件
			uni.$on('finish',()=>{
				selectedId.value = -1;
				showTranslation.value = false;
				isFinished.value = true;
				wordsList.value = [];
				//需延迟 不然更不自带头部标题
				setTimeout(()=>{
					uni.setNavigationBarTitle({
						title: "学新后检测",
						success: () => {
							console.log("设置标题成功")
						},
						fail: () => {
							console.log("设置标题失败")
						}
						
					})
				}, 100);

				//从studyInfoStore中获取选择单词列表
				let arr = studyInfoStore.studyWordsList;
				let wordBank = uni.getStorageSync(studyInfoStore.wordBankId)
				//根据number从词库中赛选单词
				// arr.forEach((item)=>{
				// 	// wordsList.value.push(words.find(word => word.number === item))
				// 	let temp = wordBank.find(word => word.number === item);
				// 	console.log(temp)
				// 	wordsList.value.push({...item, statu: 0})
				// 	// wordsList.value.push({id:temp.id, word:temp.word, statu: 0});
				// })
				
				wordsList.value = arr.map(item => {
					let temp = wordBank.find(word => word.number === item);
					return {...temp, statu: 0}
				})
				
				console.log(wordsList.value)
				
			})
		} else if(studyInfoStore.studyMode === 1){
			setTimeout(()=>{
				uni.setNavigationBarTitle({
					title: "复习后检测",
					success: () => {
						console.log("设置标题成功")
					},
					fail: () => {
						console.log("设置标题失败")
					}
					
				})
			}, 100);
		}
		
	})
	
	onUnload(()=>{
		console.log("鞋子啊");
		
		// 移除监听事件
		uni.$off('countdownFinished');
		// 移除监听事件
		uni.$off('finish'); 
	})
	
    async function onConfirmSub() {
		startTimer();
		await summitEvent(true)
		subTimesDialog.value.close();
	}
	
	async function onRejectSub() {
		startTimer();
		await summitEvent(false)
		subTimesDialog.value.close();
	}
	
	function onCloseSubDialog(){
		subTimesDialog.value.close();
	}
	
	function onClickItem(number, word) {
		console.log("出发发发")
		
		if (selectedId.value === number) {
		    showTranslation.value = !showTranslation.value;
		} else {
		    showTranslation.value = false;
		}
		selectedId.value = number;
		
		// let tempWord = word.trim()
		let tempWord = word
		if(tempWord.includes('/')) {
			let regex = /(\b[A-Za-z.]+)\s*(?=\/)/g;
			tempWord = tempWord.match(regex)[0];
		} else if(tempWord.includes('(')) {
			let regex = /(\b[A-Za-z.]+)\s*(?=\()/g;
			tempWord = tempWord.match(regex)[0];
		}
		
		tempWord = tempWord.replace(/-+/g, ' ').trim()
		
		voiceplay(tempWord);
	}
	
	//音频播放 type=0是英音，1是美音
	function voiceplay(key) {
	    uni.showLoading({
	        title: '加载中',
	    })
	    const innerAudioContext = uni.createInnerAudioContext();
	    innerAudioContext.autoplay = true;
	    // http://dict.youdao.com/dictvoice?type=0&audio=' + key; key 是需要发音的单词，链接就是有道词典的接口链接，返回就是一个音频，直接可以播放，可以直接在游览器打开。
	    innerAudioContext.src = 'http://dict.youdao.com/dictvoice?type=0&audio=' + key;
	    innerAudioContext.onPlay(() => {
	        console.log('开始播放');
	        uni.hideLoading();
	    });
	    innerAudioContext.onError((res) => {
	        console.log(res.errMsg);
	        console.log(res.errCode);
	        uni.hideLoading();
	    });
	    uni.hideLoading();
	}
	
	
	// 随机抽取数据的方法
	function getRandomItems(array, count) {
	    // 首先复制数组，避免修改原数组
	    let copiedArray = array.slice();
	
	    // 用于存储随机抽取的数据
	    let result = [];
	
	    // 循环抽取指定数量的数据
	    for (let i = 0; i < count; i++) {
	        // 如果数组为空，跳出循环
	        if (copiedArray.length === 0) break;
	
	        // 随机生成一个索引
	        let randomIndex = Math.floor(Math.random() * copiedArray.length);
	
	        // 将随机选中的数据添加到结果数组中
	        result.push(copiedArray[randomIndex]);
	
	        // 从复制的数组中移除已经选中的数据
	        copiedArray.splice(randomIndex, 1);
	    }
	
	    return result;
	}
	
	// 顺序抽取数据的方法
	function getOrderItems(array, count) {
	    // 首先复制数组，避免修改原数组
	    let copiedArray = array.slice();
	
	    // 用于存储随机抽取的数据
	    let result = [];
	
	    // 循环抽取指定数量的数据
	    for (let i = 0; i < count; i++) {
	        // 如果数组为空，跳出循环
	        if (copiedArray.length === 0) break;
	
	        // 顺序索引
	        let orderIndex = i;
	
	        // 将顺序选中的数据添加到结果数组中
	        result.push(copiedArray[orderIndex]);
	
	    }
	
	    return result;
	}
	
	//认识单词
	function onConfirm(number){
		console.log("确认");
		selectedId.value = -1;
		showTranslation.value = false;
		wordsList.value.find(temp => temp.number === number).statu = 1;
	}
	
	//不认识单词
	function onDeny(number){
		console.log("否认");
		selectedId.value = -1;
		showTranslation.value = false;
		wordsList.value.find(temp => temp.number === number).statu = 2;
	}
	
	function wordsCount(){
		return wordsList.value.filter(item => item.statu === 2).length;
	}
	
	//开始识记 跳转下一页
	async function startRemember() {
		console.log("开始识记");
		uni.showLoading({
			title:"正在加载",
			mask: true
		})
		let unknownWordList = [];
		//用于请求
		let studyWordsList = [];
		wordsList.value.forEach((item, index) => {
			if(item.statu == 1) {
				studyWordsList.push({
					word: item.word,
					known: true
				});
			}
			else if(item.statu == 2){
				unknownWordList.push(item.number);
				//todo 请求增加已学单词
				studyWordsList.push({
					word: item.word,
					forget: true,
					known: false,
					studyedNum: 0
				});
			}
		})
		if(unknownWordList.length === 0){
			if(studyWordsList.length === 0){
				uni.showToast({
					title: "未选择单词",
					icon:"error"
				})
				return;
			}
			if(userInfoStore.userInfo.role === 0) {
				const res = await uniCloud.callFunction({
					name: "addNewStudyWord",
					data: {
						relateUuid: userInfoStore.userInfo.uuid,
						wordBankId: studyInfoStore.wordBankId,
						studyedWords: studyWordsList
					}
				})
				const perDayRes = await uniCloud.callFunction({
					name: "updatePerDayStudy",
					data: {
						relateUuid: userInfoStore.userInfo.uuid,
						wordBankId: studyInfoStore.wordBankId,
						studyCount: wordsList.value.filter(item => item.statu === 1).length
					}
				})
			}else if(userInfoStore.userInfo.role === 1){
				const res = await uniCloud.callFunction({
					name: "addNewStudyWord",
					data: {
						relateUuid: userInfoStore.selectedStudentInfo.uuid,
						wordBankId: studyInfoStore.wordBankId,
						studyedWords: studyWordsList
					}
				})
				const perDayRes = await uniCloud.callFunction({
					name: "updatePerDayStudy",
					data: {
						relateUuid: userInfoStore.selectedStudentInfo.uuid,
						wordBankId: studyInfoStore.wordBankId,
						studyCount: wordsList.value.filter(item => item.statu === 1).length
					}
				})
			}
			uni.showToast({
				title: "没有生词",
				icon:"error"
			})
			uni.navigateBack()
			return;
		}
		
		/// mark01
		if(userInfoStore.userInfo.role === 0) {
			const res = await uniCloud.callFunction({
				name: "addNewStudyWord",
				data: {
					relateUuid: userInfoStore.userInfo.uuid,
					wordBankId: studyInfoStore.wordBankId,
					studyedWords: studyWordsList
				}
			})
			const perDayRes = await uniCloud.callFunction({
				name: "updatePerDayStudy",
				data: {
					relateUuid: userInfoStore.userInfo.uuid,
					wordBankId: studyInfoStore.wordBankId,
					studyCount: wordsList.value.filter(item => item.statu === 1).length
				}
			})
		} else if(userInfoStore.userInfo.role === 1){
			const res = await uniCloud.callFunction({
				name: "addNewStudyWord",
				data: {
					relateUuid: userInfoStore.selectedStudentInfo.uuid,
					wordBankId: studyInfoStore.wordBankId,
					studyedWords: studyWordsList
				}
			})
			const perDayRes = await uniCloud.callFunction({
				name: "updatePerDayStudy",
				data: {
					relateUuid: userInfoStore.selectedStudentInfo.uuid,
					wordBankId: studyInfoStore.wordBankId,
					studyCount: wordsList.value.filter(item => item.statu === 1).length
				}
			})
		}

		
		studyInfoStore.setStudyWordsList(unknownWordList);

		wordsList.value = []
		uni.navigateTo({
			url:"/pages/memorize-words/memorize-words"
		})
		
		uni.hideLoading();
	}
	
	// 启动定时器
	const startTimer = () => {
	  timer.value = setTimeout(() => {
		uni.showToast({
			title: "请求超时",
			icon: "error"
		})
	  }, 10000)
	}
	
	// 清除定时器
	const clearTimer = () => {
	  if (timer.value) {
	    clearTimeout(timer.value)
	    timer.value = null
	  }
	}
	
	//完成后提交
	async function onSummit(){
		if(wordsList.value.some(item => item.statu === 0)){
			uni.showToast({
				title: "存在未选单词",
				icon: "error"
			})
			return;
		}
		
		if(userInfoStore.userInfo.role === 1) {
			subTimesDialog.value.open();
		} else {
			await summitEvent(false)
		}
	}
	
	async function summitEvent(isSubTimes) {
		uni.showLoading({
			title:"正在提交",
			mask: true
		})
		
		let studyedWords = wordsList.value.map(item => {
			return {
				word: item.word, 
				statu: item.statu
			}
		});
		console.log(studyedWords)
		
		let stopTime = Date.now()
		
		let title = studyInfoStore.allWordBankInfo.find(item => item.wordBankId === studyInfoStore.wordBankId).title
		
		/// mark01
		if(userInfoStore.userInfo.role === 0) {
			
			const res = await uniCloud.callFunction({
				name: "updateStudyedwords",
				data: {
					relateUuid: userInfoStore.userInfo.uuid,
					wordBankId: studyInfoStore.wordBankId,
					studyedWords: studyedWords
				}
			})
			
			let tempAccuracy = wordsList.value.filter(item => item.statu === 1).length / wordsList.value.length * 100;
			
			if(studyInfoStore.studyMode === 1) {
				
				const perDayRes = await uniCloud.callFunction({
					name: "updatePerDayReview",
					data: {
						relateUuid: userInfoStore.userInfo.uuid,
						wordBankId: studyInfoStore.wordBankId,
						reviewCount: studyedWords.length
					}
				})
				
				const addFeedbackRes = await uniCloud.callFunction({
					name: "addFeedback",
					data: {
						relateUuid: userInfoStore.userInfo.uuid,
						wordBankId: studyInfoStore.wordBankId,
						title: title,
						username: userInfoStore.userInfo.userName,
						mode: studyInfoStore.studyMode,
						studyCount: studyedWords.length,
						wrongCount: studyedWords.filter(item => item.statu === 2).length,
						accuracy: accuracy.value,
						forgettingRate: forgettingRate.value,
						words: wordsList.value.map(item => item.number),
						startTime: countdownStore.startTime,
						stopTime: stopTime,
						spendTime: stopTime - countdownStore.startTime,
						comment: createComment(studyInfoStore.studyMode, accuracy.value, studyedWords.length, studyedWords.filter(item => item.statu === 2).length),
						
					}
				})
				feedbackId = addFeedbackRes.result.id
			} else if (studyInfoStore.studyMode === 0) {
				const perDayRes = await uniCloud.callFunction({
					name: "updatePerDayStudy",
					data: {
						relateUuid: userInfoStore.userInfo.uuid,
						wordBankId: studyInfoStore.wordBankId,
						studyCount: studyedWords.length
					}
				})
				const addFeedbackRes = await uniCloud.callFunction({
					name: "addFeedback",
					data: {
						relateUuid: userInfoStore.userInfo.uuid,
						wordBankId: studyInfoStore.wordBankId,
						title: title,
						username: userInfoStore.userInfo.userName,
						mode: studyInfoStore.studyMode,
						studyCount: studyedWords.length,
						wrongCount: studyedWords.filter(item => item.statu === 2).length,
						accuracy: accuracy.value,
						forgettingRate: forgettingRate.value,
						words: wordsList.value.map(item => item.number),
						startTime: countdownStore.startTime,
						stopTime: stopTime,
						spendTime: stopTime - countdownStore.startTime,
						comment: createComment(studyInfoStore.studyMode, accuracy.value, studyedWords.length, studyedWords.filter(item => item.statu === 2).length),
					}
				})
				feedbackId = addFeedbackRes.result.id
			}
			
			
		} else if(userInfoStore.userInfo.role === 1){
			const res = await uniCloud.callFunction({
				name: "updateStudyedwords",
				data: {
					relateUuid: userInfoStore.selectedStudentInfo.uuid,
					wordBankId: studyInfoStore.wordBankId,
					studyedWords: studyedWords
				}
			})
			if(studyInfoStore.studyMode === 1) {
				const perDayRes = await uniCloud.callFunction({
					name: "updatePerDayReview",
					data: {
						relateUuid: userInfoStore.selectedStudentInfo.uuid,
						wordBankId: studyInfoStore.wordBankId,
						reviewCount: studyedWords.length
					}
				})
				
				const addFeedbackRes = await uniCloud.callFunction({
					name: "addFeedback",
					data: {
						relateUuid: userInfoStore.selectedStudentInfo.uuid,
						wordBankId: studyInfoStore.wordBankId,
						title: title,
						username: userInfoStore.selectedStudentInfo.userName,
						mode: studyInfoStore.studyMode,
						studyCount: studyedWords.length,
						wrongCount: studyedWords.filter(item => item.statu === 2).length,
						accuracy: accuracy.value,
						forgettingRate: forgettingRate.value,
						words: wordsList.value.map(item => item.number),
						startTime: countdownStore.startTime,
						stopTime: stopTime,
						spendTime: stopTime - countdownStore.startTime,
						comment: createComment(studyInfoStore.studyMode, accuracy.value, studyedWords.length, studyedWords.filter(item => item.statu === 2).length),
						
					}
				})
				
				if(isSubTimes) {
					const updateTimesRes = await uniCloud.callFunction({
						name: "updateTimes",
						data: {
							uuid: userInfoStore.selectedStudentInfo.uuid,
							value: -1,
							mode: studyInfoStore.studyMode
						}
					})
				}
				
				feedbackId = addFeedbackRes.result.id
				
			} else if (studyInfoStore.studyMode === 0) {
				const perDayRes = await uniCloud.callFunction({
					name: "updatePerDayStudy",
					data: {
						relateUuid: userInfoStore.selectedStudentInfo.uuid,
						wordBankId: studyInfoStore.wordBankId,
						studyCount: studyedWords.length
					}
				})
				
				const addFeedbackRes = await uniCloud.callFunction({
					name: "addFeedback",
					data: {
						relateUuid: userInfoStore.selectedStudentInfo.uuid,
						wordBankId: studyInfoStore.wordBankId,
						title: title,
						username: userInfoStore.selectedStudentInfo.userName,
						mode: studyInfoStore.studyMode,
						studyCount: studyedWords.length,
						wrongCount: studyedWords.filter(item => item.statu === 2).length,
						accuracy: accuracy.value,
						forgettingRate: forgettingRate.value,
						words: wordsList.value.map(item => item.number),
						startTime: countdownStore.startTime,
						stopTime: stopTime,
						spendTime: stopTime - countdownStore.startTime,
						comment: createComment(studyInfoStore.studyMode, accuracy.value, studyedWords.length, studyedWords.filter(item => item.statu === 2).length),
					}
				})
				
				if(isSubTimes) {
					const updateTimesRes = await uniCloud.callFunction({
						name: "updateTimes",
						data: {
							uuid: userInfoStore.selectedStudentInfo.uuid,
							value: -1,
							mode: studyInfoStore.studyMode
						}
					})
				}
				
				feedbackId = addFeedbackRes.result.id
			}
		}
		
		
		if(studyInfoStore.studyMode === 0) {
			// uni.navigateBack();
			let editMode = 0;
			if(userInfoStore.userInfo.role === 1){
				editMode = 1;
			}
			uni.redirectTo({
				url: `/pages/feedback-detail/feedback-detail?feedbackId=${feedbackId}&editMode=${editMode}`,
				success: (res) => {
					console.log('跳转成功', res);
					clearTimer();
				},
			})
		} else if(studyInfoStore.studyMode === 1){
			// uni.navigateBack(
			// 	{
			// 		delta: 2
			// 	}
			// );
			// uni.navigateTo({
			// 	url: "/pages/feedback-detail/feedback-detail"
			// }))
			let editMode = 0;
			if(userInfoStore.userInfo.role === 1){
				editMode = 1;
			}
			uni.redirectTo({
				url: `/pages/feedback-detail/feedback-detail?feedbackId=${feedbackId}&editMode=${editMode}`,
				success: (res) => {
					console.log('跳转成功', res);
					clearTimer();
				},
			})
		}
		
		uni.hideLoading()
	}

	function createComment(mode, accuracy, count, wrongCount) {
		let comment = "";
		let diff = "";
		if(mode === 0) {
			diff = "学新"
		} else {
			diff = "复习"
		}
		
		if(parseFloat(accuracy) >= 80) {
			comment = "太棒了！"
		} else if(parseFloat(accuracy) >= 60) {
			comment = "表现不错！"
		} else{
			comment = "遗忘单词比较多，"
		}
		comment = comment + `本次${diff}${count}个单词，其中错误${wrongCount}个，准确率为${accuracy}%`
		if(parseFloat(accuracy) >= 80) {
			comment = comment + "请继续保持。"
		} else if(parseFloat(accuracy) >= 60) {
			comment = comment + "请继续努力。"
		} else{
			comment = comment + "请及时前往反馈列表查看学习内容。"
		}
		console.log(comment)
		return comment;
	}

	function onCloseDialog(){
		tipsDialog.value.close();
	}
</script>

<style lang="scss" scoped>
	.layout{
		background-color: #F5F5F5;
		height: 100vh;
		position: relative;
		.content{
			padding: 20rpx;
			.countdown{
				font-size: 50rpx;
				color: #18BB7C;
			}
			.scrollView{
				height: 80vh;
				.active-item{
					display: flex;
					background-color: white;
					margin: 20rpx 0;
					padding: 20rpx;
					font-size: 24px;
					border: 1px solid green;
					gap: 30rpx;
					flex-direction: column;
					.itemTop{
						display: flex;
						flex-direction: row;
						justify-content: space-between;
						text{
							width: 65%;
							word-break: break-all;
						}
						.iconBtnRow{
							display: flex;
							align-items: center;
							gap: 30rpx;
							.leftBtn{
								background-color: #18BB7C;
								padding: 10rpx;
								border-radius: 50%;
							}
							.inactive-leftBtn{
								background-color: #94938F;
								padding: 10rpx;
								border-radius: 50%;
							}
							.rightBtn{
								background-color: #F6465D;
								padding: 10rpx;
								border-radius: 50%;
							}
							.inactive-rightBtn{
								background-color: #94938F;
								padding: 10rpx;
								border-radius: 50%;
							}
						}
					}
					.itemBottom{
						display: flex;
						justify-content: center;
						word-break: break-all;
					}
				}
				.item{
					display: flex;
					background-color: white;
					margin: 20rpx 0;
					padding: 20rpx;
					font-size: 24px;
					gap: 30rpx;
					flex-direction: column;
					.itemTop{
						display: flex;
						flex-direction: row;
						justify-content: space-between;
						text{
							width: 65%;
							word-break: break-all;
						}
						.iconBtnRow{
							display: flex;
							align-items: center;
							gap: 30rpx;
							.leftBtn{
								background-color: #18BB7C;
								padding: 10rpx;
								border-radius: 50%;
							}
							.inactive-leftBtn{
								background-color: #94938F;
								padding: 10rpx;
								border-radius: 50%;
							}
							.rightBtn{
								background-color: #F6465D;
								padding: 10rpx;
								border-radius: 50%;
							}
							.inactive-rightBtn{
								background-color: #94938F;
								padding: 10rpx;
								border-radius: 50%;
							}
						}
					}
					.itemBottom{
						display: flex;
						justify-content: center;
						word-break: break-all;
					}
				}

			}
			
		}
		.bottom{
			background-color: white;
			padding: 20rpx 40rpx 100rpx 40rpx;
			position: absolute;
			width: 100%;
			box-sizing: border-box;
			bottom: 0;
			display: flex;
			flex-direction: row;
			justify-content: space-between;
			
			text{
				font-size: 24px;
			}
			.statistics{
				display: flex;
				gap: 20rpx;
				align-items: center;

				.statisticsItem{
					display: flex;
					gap: 5rpx;
					.label{
						color: #18BB7C;
					}
					.value{
						color: red;
					}
				}

			}
			.bottomBtn{
				border: 1rpx solid black;
				border-radius: 50rpx;
				padding: 10rpx 20rpx;
				display: flex;
				justify-content: center;
				align-items: center;
			}
		}
		.tipsDialog{
			display: flex;
			flex-direction: column;
			align-items: center;
			gap: 30rpx;
			.dialogContent{
				display: flex;
				flex-direction: column;
				align-items: center;
				padding: 40rpx;
				background-color: white;
				border-radius: 50rpx;
				.dialogTitle{
					margin-bottom: 50rpx;
					padding: 15rpx 50rpx;
					border-radius: 50rpx;
					background-color: #18BB7C;
					color: white;
					font-size: 24px;
				}

				.textIconColumn{
					display: flex;
					flex-direction: column;
					gap: 30rpx;
					text{
						color: black;
						font-size: 20px;
					}
					.textIconRow{
						display: flex;
						gap: 20rpx;
						align-items: center;
						.rightBtn{
							background-color: #18BB7C;
							padding: 10rpx;
							border-radius: 50%;
						}
						.wrongBtn{
							background-color: #F6465D;
							padding: 10rpx;
							border-radius: 50%;
						}
					}
				}
					
				.bottomTip{
					margin-top: 60rpx;
					padding: 10rpx 40rpx;
					border-radius: 50rpx;
					border: 1rpx solid #efdd9c;
					background-color: #fce98c;
					text{
						font-size: 18px;
					}
				}
			}
			
		}
		.subTimesDialog{
			display: flex;
			flex-direction: column;
			align-items: center;
			gap: 60rpx;
			.dialogContent{
				display: flex;
				flex-direction: column;
				align-items: center;
				padding: 40rpx;
				background-color: white;
				border-radius: 50rpx;
				.dialogTitle{
					margin-bottom: 80rpx;
					padding: 15rpx 50rpx;
					border-radius: 50rpx;
					background-color: #18BB7C;
					color: white;
					font-size: 24px;
				}
				text{
					color: red;
					font-size: 24px;
				}
				.btnRow{
					display: flex;
					flex-direction: row;
					gap: 20rpx;
					color: white;
					font-size: 26px;
					margin-top: 50rpx;
					.btnLeft{
						padding: 20rpx 50rpx;
						background-color: #18BB7C;
						border-radius: 50rpx;
					}
					.btnRight{
						padding: 20rpx 50rpx;
						background-color: orange;
						border-radius: 50rpx;
					}
				}
			}
			
		}
	}
</style>
